package com.gemme.gemme.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.shequ.BrandNewFragment;
import com.gemme.gemme.shequ.FmPagerAdapter;
import com.gemme.gemme.shequ.ProductFragment;
import com.gemme.gemme.view.BrandListBottomView;
import com.gemme.gemme.view.BrandListHeadView;
import com.gemme.gemme.view.BrandListMiddleView;
import com.gemme.gemme.view.XuanTingView;
import com.google.android.material.tabs.TabLayout;
import com.jaeger.library.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;


public class BrandListActivity extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_brand_list);
        initTop();
        initView();
        getDataS();
        getIntentData();

    }
    String brandLogo;
    private void getIntentData() {
        try {
            String brandName = getIntent().getStringExtra("brandName");
            brandLogo = getIntent().getStringExtra("brandLogo");
            brandListHeadView.setBrandLogo(brandLogo);
            brandListBottomView.setBrandName(brandName);
            brandListBottomView.setType("remode",null,null,null);
        }catch (Exception e){

        }
    }

    private void getDataS() {

    }

    XuanTingView xtview;
    BrandListBottomView brandListBottomView;
    BrandListMiddleView brandListMiddleView;
    BrandListHeadView brandListHeadView;
    private void initView() {
        brandListHeadView = new BrandListHeadView(this);

        brandListMiddleView = new BrandListMiddleView(this);


        brandListBottomView = new BrandListBottomView(this);
        xtview = findViewById(R.id.xtview);
        xtview.addHeadView(brandListHeadView);
        xtview.addMiddleView(brandListMiddleView);
        xtview.addBottomView(brandListBottomView);
//        brandListMiddleView.setBrandLogo(brandLogo);



        initTabLayout();
        brandListBottomView.setOnDataChange(new BrandListBottomView.OnDataChange() {
            @Override
            public void onDataChange(ProductListBean productListBean) {
                try {
                    List<ProductListBean.DataBean.ProductEsVoListBean> productEsVoList = productListBean.getData().getEsProductInfoList();
                    int size = productEsVoList.size();
                    if(productEsVoList!=null&&size!=0){
                        brandListHeadView.setTv_num(productEsVoList.get(0).getBrandName());
                    }
                }catch (Exception e){

                }
            }
        });
    }
    private void initTabLayout() {
        brandListMiddleView.getTabLayout().addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                String tabText = tab.getText() + "";
                switch (tabText){
                    case "推荐":
                        brandListBottomView.setType("remode",null,null,null);
                        break;

                    case "热销":
                        brandListBottomView.setType(null,"soldNum-desc",null,null);
                        break;

                    case "价格":
                        brandListBottomView.setType(null,null,"price-desc",null);
                        break;

                    case "折扣":
                        brandListBottomView.setType(null,null,null,"discount");
                        break;
                }

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }


    private void initTop() {
        StatusBarUtil.setTransparent(this);
    }





}